#ifndef __PACKET_HANDLER_H__
#define __PACKET_HANDLER_H__

#include <FunctionMap.h>
using namespace util;

class ServerSession;
class UserSession;

class PacketHandler
{
	typedef VOID (*fnHandler)( ServerSession * pSession, MSG_BASE * pMsg, WORD wSize );
	typedef VOID (*fnHandler_c)( UserSession * pSession, MSG_BASE * pMsg, WORD wSize );

public:
	PacketHandler();
	~PacketHandler();

	VOID			ParsePacket_CA( UserSession * pSession, MSG_BASE * pMsg, WORD wSize );
	VOID			ParsePacket_AD( ServerSession * pSession, MSG_BASE * pMsg, WORD wSize );
	VOID			ParsePacket_AM( ServerSession * pSession, MSG_BASE * pMsg, WORD wSize );
	VOID			ParsePacket_AG( ServerSession * pSession, MSG_BASE * pMsg, WORD wSize );
	VOID			ParsePacket_AU( ServerSession * pSession, MSG_BASE * pMsg, WORD wSize );	
	VOID			ParsePacket_AW( ServerSession * pSession, MSG_BASE * pMsg, WORD wSize );	
	VOID			ParsePacket_AZ( ServerSession * pSession, MSG_BASE * pMsg, WORD wSize );	

private:
	BOOL			ResisterHandler_CA();
	BOOL			ResisterHandler_AD();
	BOOL			ResisterHandler_AM();
	BOOL			ResisterHandler_AG();
	BOOL			ResisterHandler_AU();
	BOOL			ResisterHandler_AW();
	BOOL			ResisterHandler_AZ();

	BOOL			AddHandler_CA( BYTE category, BYTE protocol, fnHandler_c fnHandler );
	BOOL			AddHandler_AD( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_AM( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_AG( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_AU( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_AW( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_AZ( BYTE category, BYTE protocol, fnHandler fnHandler );

	struct FUNC_CA : public BASE_FUNC
	{
		fnHandler_c	m_fnHandler;
	};
	struct FUNC_AD : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_AM : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_AG : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_AU : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_AW : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_AZ : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};

	FunctionMap	*	m_pFuncMap_CA;
	FunctionMap	*	m_pFuncMap_AD;
	FunctionMap	*	m_pFuncMap_AM;
	FunctionMap	*	m_pFuncMap_AG;
	FunctionMap	*	m_pFuncMap_AU;
	FunctionMap	*	m_pFuncMap_AW;
	FunctionMap	*	m_pFuncMap_AZ;
};

extern PacketHandler g_PacketHander;

#endif // __PACKET_HANDLER_H__